(function() {
  var $asiance, $body, $contact, $container, $features, $home, $intlinks, $lang, $livestream, $load, $menu, $menulinks, $panes, $project, $showhide, $window, $workimages, contact_loaded, disable_modal, options, resized, scrollElement, timer_track_page;
  $load = $("#loading");
  $("html").removeClass("no-js").addClass("js");
  $(window).load(function() {
    return $load.delay(1500).fadeOut(1000);
  });
  window.lang = $("html").attr("lang");
  window.current_page = "";
  if ($.browser.webkit) {
    scrollElement = "body";
  } else {
    scrollElement = "html";
  }
  options = {
    modal: true,
    width: "740",
    height: "420",
    autoOpen: false,
    closeText: "",
    draggable: false,
    resizable: false,
    hide: "fade",
    show: "fade",
    position: ["center", "center"],
    cur: 0,
    open: function() {
      $(".workimages").css({
        left: 0
      });
      return options.cur = 0;
    }
  };
  $panes = $(".pane", $("#container"));
  $container = $("#container");
  $home = $("#home", $("#container"));
  $features = $home.find("ul li");
  $showhide = $(".showhide li");
  $project = $(".project", $("#projects"));
  $contact = $("#contact", $("#container"));
  $livestream = $("#livestream", $("#container"));
  $workimages = null;
  $lang = $("#lang");
  $menu = $("#menu");
  $menulinks = $("#menu a");
  $intlinks = $("nav a[href^=#]");
  $asiance = $(".asiance", $("#header"));
  $window = $(window);
  $body = $("body");
  timer_track_page = 0;
  contact_loaded = 0;
  disable_modal = 1;
  resized = "0";
  window.Asiance = {
    initialize: function() {
      var didResize, self;
      self = this;
      if (typeof document.location.hash.split("#")[1] === "undefined") {
        window.current_page = "home";
      } else {
        window.current_page = document.location.hash.split("#")[1];
      }
      self.track_page();
      self.init_asiance();
      self.detect_resolution();
      self.resize();
      self.make_wall();
      $livestream.isotope();
      if (navigator.userAgent.match(/iPad/i)) {
        window.iPad = true;
        return self.init_ipad();
      } else {
        self.init_browsers();
        self.show_nav();
        self.reposition();
        didResize = false;
        $(window).resize(function() {
          return didResize = true;
        });
        setInterval((function() {
          if (didResize) {
            didResize = false;
            self.detect_resolution();
            self.resize();
            self.make_wall();
            return self.reposition();
          }
        }), 250);
        $window.load(function() {
          return self.animate_menu();
        });
        return $(document).keydown(self.key_nav);
      }
    },
    track_page: function() {
      return _gaq.push(["_trackPageview", "/" + window.lang + "/" + window.current_page]);
    },
    update_hash: function() {
      return document.location.hash = "#" + window.current_page;
    },
    validate_email: function(email) {
      var re;
      re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
      return re.test(email);
    },
    rotate: function() {
      return $workimages.stop(true, true).animate({
        left: -(options.cur * 450)
      }, 200);
    },
    init_asiance: function() {
      var $award, $nextimg, $previmg, self;
      self = this;
      $lang.find("li").click(function(event) {
        var lang;
        lang = $(this).attr("class");
        $("#language").find("option:selected").removeAttr("selected");
        $("#language").find("option[value=" + lang + "]").attr("selected", "selected");
        $("#change_lang").submit();
        return false;
      });
      $home.find(".dior .more").bind("click", function() {
        $("#modal3").dialog(options);
        $("#modal3").dialog("open");
        return false;
      });
      $home.find(".longchamp .more").bind("click", function() {
        $("#modal4").dialog(options);
        $("#modal4").dialog("open");
        return false;
      });
      $home.find(".renault .more").bind("click", function() {
        $("#modal10").dialog(options);
        $("#modal10").dialog("open");
        return false;
      });
      $home.find(".lacoste .more").bind("click", function() {
        $("#modal0").dialog(options);
        $("#modal0").dialog("open");
        return false;
      });
      $showhide.not(":first").addClass("cross").children("p").hide().end().end().children("h3").bind("click", function() {
        var $this;
        $this = $(this);
        return $this.parent("li").toggleClass("cross").find("p").slideToggle("slow").end().siblings().addClass("cross").find("p").hide("slow");
      });
      $award = $(".award", $("#about"));
      $award.hover((function() {
        return $(this).children("div:first").stop(true, true).fadeOut("slow").next("div").stop(true, true).fadeIn("slow");
      }), function() {
        return $(this).children("div:first").stop(true, true).fadeIn("slow").next("div").stop(true, true).fadeOut("slow");
      });
      $project.append("<span class=\"shadowr\"></span><span class=\"shadowb\"></span>");
      $livestream.children("li").append("<span class=\"shadowr\"></span><span class=\"shadowb\"></span>");
      $(".ui-widget-overlay").live("click", function() {
        return $(".modal").dialog("close");
      });
      $workimages = $(".workimages", $("#work"));
      $nextimg = $(".nextw");
      $previmg = $(".prevw");
      $nextimg.bind("click", function(event) {
        options.cur++;
        if (options.cur === 4) {
          options.cur = 0;
        }
        self.rotate();
        return false;
        return event.preventDefault();
      });
      $previmg.bind("click", function(event) {
        options.cur--;
        if (options.cur === -1) {
          options.cur = 3;
        }
        self.rotate();
        return false;
        return event.preventDefault();
      });
      $contact.find(".email").click(function() {
        $contact.find(".send-me").css("height", $(this).height()).slideToggle("slow");
        return false;
      });
      return $contact.find(".send-me input[type=\"submit\"]").click(function() {
        var mail;
        mail = $contact.find(".send-me input[type=\"text\"]").attr("value");
        if (self.validate_email(mail)) {
          $.ajax({
            url: $('#mail-map').attr("href"),
            type: "POST",
            data: "mail=" + mail,
            success: function(data, textStatus, jqXHR) {
              if (parseInt(data) === 1) {
                return $contact.find(".send-me input[type=\"text\"]").attr("value", "Thank you, directions have been sent to your email.").focus(function() {
                  return $(this).attr("value", "");
                });
              } else {
                return $contact.find(".send-me input[type=\"text\"]").attr("value", "Oops something wrong happened").focus(function() {
                  return $(this).attr("value", "");
                });
              }
            }
          });
        } else if (mail.indexOf("Check") === -1) {
          $(this).prev().attr("value", mail + " <-- Check your email!").focus(function() {
            $(this).attr("value", mail);
          });
        }
        return false;
      });
    },
    init_browsers: function() {
      var self;
      self = this;
      $window.bind("hashchange", function(event) {
        event.preventDefault();
        return false;
      });
      $intlinks.bind("click", function(event) {
        var $anchor;
        event.preventDefault();
        $anchor = $(this);
        $(scrollElement).stop().animate({
          scrollLeft: $("#" + $anchor.attr("title")).offset().left
        }, 600, "swing", function() {
          return self.make_active();
        });
        clearTimeout(timer_track_page);
        window.current_page = $anchor.attr("title");
        timer_track_page = setTimeout("window.Asiance.track_page()", 2000);
        setTimeout("window.Asiance.update_hash()", 1000);
        return $(".modal").dialog("close");
      });
      $asiance.bind("click", function(event) {
        event.preventDefault();
        $(scrollElement).stop().animate({
          scrollLeft: 0
        }, 600, "swing", function() {
          return self.make_active();
        });
        clearTimeout(timer_track_page);
        window.current_page = $(this).attr("title");
        timer_track_page = setTimeout("window.Asiance.track_page()", 2000);
        return setTimeout("window.Asiance.update_hash()", 1000);
      });
      $(scrollElement).bind("mousewheel", function(event, delta) {
        if (delta > 0) {
          $(".active").prev().click();
          event.preventDefault();
        } else {
          $(".active").next().click();
          event.preventDefault();
        }
        return false;
      });
      return $features.hover((function() {
        return $(this).find(".more").stop(true, true).fadeIn();
      }), function() {
        return $(this).find(".more").stop(true, true).hide();
      });
    },
    init_ipad: function() {
      var loaded, self;
      self = this;
      loaded = function() {
        var currentPage, myScroll;
        currentPage = 0;
        myScroll = new iScroll("scroller", {
          hScrollbar: false,
          vScrollbar: false,
          vScroll: false,
          snap: ".pane",
          snapThreshold: 70,
          momentum: false,
          bounce: false,
          lockDirection: true,
          useTransition: true,
          onScrollEnd: function() {
            $(".active").removeClass("active");
            $("#menu a:nth-child(" + (this.currPageX + 1) + ")").addClass("active");
            clearTimeout(timer_track_page);
            window.current_page = $("#menu a:nth-child(" + (this.currPageX + 1) + ")").attr("title");
            timer_track_page = setTimeout("window.Asiance.track_page()", 2000);
            return currentPage = this.currPageX;
          }
        });
        $menulinks.bind("click", function(event) {
          var pagenumber;
          pagenumber = $(this).index();
          myScroll.scrollToPage(pagenumber, 0, 1000);
          return event.preventDefault();
        });
        $asiance.bind("click", function(event) {
          myScroll.scrollToPage(0, 0, 1000);
          return event.preventDefault();
        });
        $body.bind("touchmove", function(event) {
          return event.preventDefault();
        });
        $window.bind("orientationchange", function(event) {
          $load.show();
          self.detect_orientation();
          self.resize();
          myScroll.refresh();
          myScroll.scrollToPage(currentPage, 0, 200);
          self.make_wall();
          $livestream.isotope("destroy");
          $livestream.isotope();
          return $load.delay(1000).fadeOut();
        });
        return true;
      };
      $body.addClass("ipad");
      $container.wrap("<div id=\"scroller\" />");
      self.detect_orientation();
      self.asiance_map();
      self.make_modal();
      return $window.load(loaded);
    },
    make_modal: function() {
      return $project.each(function(index) {
        return $(".link" + index).click(function() {
          $("#modal" + index).dialog(options);
          $("#modal" + index).dialog("open");
          return false;
        });
      });
    },
    detect_orientation: function() {
      if (orientation === 0) {
        return $body.addClass("portrait").removeClass("landscape small");
      } else if (orientation === 90) {
        return $body.removeClass("portrait").addClass("landscape");
      } else if (orientation === -90) {
        return $body.removeClass("portrait").addClass("landscape");
      } else {
        if (orientation === 180) {
          return $body.addClass("portrait").removeClass("landscape small");
        }
      }
    },
    detect_resolution: function() {
      if (($window.width() >= "1008") && ($window.height() >= "679")) {
        $body.removeClass();
      } else {
        $body.addClass("small");
      }
      if (($window.width() < "1000") && ($window.width() <= $window.height())) {
        return $body.addClass("portrait");
      } else {
        return $body.removeClass("portrait");
      }
    },
    resize: function() {
      var $magicLine, $magicLine2, pageH, pageW, paneH;
      pageH = $window.height() - 100;
      pageW = $window.width() - 60;
      paneH = pageH;
      if ((navigator.appVersion.indexOf("MSIE 7.") !== -1) && (resized === "0")) {
        $panes.width(pageW).height(paneH - 18);
        $container.width($window.width() * 8);
        $home.width(pageW + 60).height(paneH - 3);
        resized = 1;
      } else {
        $panes.width(pageW).height(paneH);
        $container.width($window.width() * 8);
        $home.width(pageW + 60).height(paneH + 15);
      }
      if ($("#magic").length && $("#magic2").length) {
        $magicLine = $("#magic");
        $magicLine2 = $("#magic2");
        $magicLine.width($(".active").outerWidth(true)).css("left", $(".active").position().left);
        return $magicLine2.width($(".active").outerWidth(true)).css("left", $(".active").position().left).data("origLeft", $magicLine.position().left).data("origWidth", $magicLine.width());
      }
    },
    animate_menu: function() {
      var $el, $magicLine, $magicLine2, leftPos, newWidth;
      $el = void 0;
      leftPos = void 0;
      newWidth = void 0;
      $menu.append("<span id=\"magic\"></span><span id=\"magic2\"></span>");
      $magicLine = $("#magic");
      $magicLine2 = $("#magic2");
      $magicLine.width($(".active").outerWidth(true)).css("left", $(".active").position().left);
      $magicLine2.width($(".active").outerWidth(true)).css("left", $(".active").position().left).data("origLeft", $magicLine.position().left).data("origWidth", $magicLine.width());
      $menulinks.hover((function() {
        $el = $(this);
        leftPos = $el.position().left;
        newWidth = $el.outerWidth(true);
        return $magicLine2.stop().animate({
          left: leftPos,
          width: newWidth
        });
      }), function() {
        return $magicLine2.stop().animate({
          left: $magicLine2.data("origLeft"),
          width: $magicLine2.data("origWidth")
        });
      });
      return $("nav a[href^=#],.asiance").click(function() {
        var $magic, target;
        target = $(this).attr("title");
        $magic = $menulinks.filter("[href=#" + target + "]");
        leftPos = $magic.position().left;
        newWidth = $magic.outerWidth(true);
        $magicLine2.data("origLeft", leftPos).data("origWidth", newWidth);
        $magicLine2.stop().animate({
          left: leftPos,
          width: newWidth
        });
        return $magicLine.stop().animate({
          left: leftPos,
          width: newWidth
        });
      });
    },
    make_active: function() {
      var $link, current, hash, self;
      self = this;
      current = self.get_clickables()[1];
      hash = current[0].id;
      $link = $menulinks.filter("[href=#" + hash + "]");
      if ($link.length && !$link.is(".active")) {
        $menulinks.removeClass("active");
        $link.addClass("active");
      }
      if (hash === "contact" && contact_loaded === 0) {
        self.asiance_map();
        contact_loaded = 1;
      }
      if (hash === "work" && disable_modal === 1) {
        self.make_modal();
        return disable_modal = 0;
      }
    },
    key_nav: function(event) {
      if (event.which === 37) {
        event.preventDefault();
        return $("#menu .active").prev().click();
      } else if (event.which === 39) {
        event.preventDefault();
        return $("#menu .active").next().click();
      }
    },
    get_clickables: function() {
      var elem_left, elem_right, paneR, scrollX, viewR, visibles, width;
      width = $window.width();
      scrollX = $(window).scrollLeft();
      viewR = scrollX + $(window).width();
      elem_left = $panes.eq(Math.floor(scrollX / width));
      elem_right = $panes.eq(Math.floor(viewR / width));
      visibles = void 0;
      if (elem_right[0]) {
        if (elem_left[0].id === elem_right[0].id) {
          visibles = elem_left;
        } else {
          visibles = elem_left.nextUntil(elem_right).andSelf().add(elem_right);
        }
      } else {
        visibles = elem_left;
      }
      if (visibles.size() > 2) {
        return [[visibles.first(), visibles.last()], visibles.eq(1)];
      }
      if (visibles.size() === 2) {
        paneR = visibles.eq(1).offset().left + visibles.eq(1).outerWidth();
        if (visibles.first().offset().left - scrollX < viewR - paneR) {
          return [[visibles.first()], visibles.eq(1)];
        } else {
          return [[visibles.eq(1)], visibles.first()];
        }
      }
      return [[], visibles.first()];
    },
    make_wall: function() {
      var $logo_container, $page_container, lognbperpage, logoHeight, logoWidth, logpercol, logperrow, nbperpage, percol, perrow, projectHeight, projectWidth;
      projectWidth = $project.outerWidth(true);
      projectHeight = $project.outerHeight(true);
      percol = parseInt(($window.width() - 30) / projectWidth);
      perrow = parseInt(($window.height() - 270) / projectHeight);
      nbperpage = percol * perrow;
      $page_container = $("#page_container");
      if (nbperpage < 4) {
        nbperpage = 4;
      }
      $page_container.width(percol * projectWidth).pajinate({
        show_first_last: false,
        items_per_page: nbperpage
      });
      $(".logo li img").each(function(index) {
        return $(this).attr('src', $(this).attr('data-picture'));
      });
      logoWidth = $(".logo li").outerWidth(true) + 4;
      logoHeight = $(".logo li").outerHeight(true);
      logpercol = parseInt(($window.width() - 60) / logoWidth);
      logperrow = parseInt(($window.height() - 300) / logoHeight);
      lognbperpage = logpercol * logperrow;
      $logo_container = $("#logo_container");
      if (lognbperpage < 4) {
        lognbperpage = 4;
      }
      $logo_container.width(logpercol * logoWidth).pajinate({
        item_container_id: ".logo",
        nav_panel_id: ".logo_navigation",
        show_first_last: false,
        items_per_page: lognbperpage
      });
      if ($(".page_navigation a").hasClass("first last")) {
        $(".page_navigation").hide();
      } else {
        $(".page_navigation").show();
      }
      if ($(".logo_navigation a").hasClass("first last")) {
        return $(".logo_navigation").hide();
      } else {
        return $(".logo_navigation").show();
      }
    },
    asiance_map: function() {
      var latlng, map, mapOptions, marker, p, rc, rv;
      if (window.lang === "ko" && !window.iPad) {
        p = new daum.maps.LatLng(37.566206, 126.972097);
        rc = new daum.maps.RoadviewClient();
        rv = new daum.maps.Roadview(document.getElementById("map_canvas"));
        return rc.getNearestPanoId(p, 50, function(panoid) {
          rv.setPanoId(panoid);
          return rv.setViewpoint({
            pan: 60,
            tilt: -22,
            zoom: -1
          });
        });
      } else {
        latlng = new google.maps.LatLng(37.5661, 126.9721);
        mapOptions = {
          zoom: 15,
          center: latlng,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
        marker = new google.maps.Marker({
          position: latlng,
          map: map,
          icon: "/images/map_marker.png"
        });
        return google.maps.event.addListener(marker, "click", function() {
          return window.open("http://maps.google.com/maps?saddr=&amp;daddr=Asiance+Seoul");
        });
      }
    },
    show_nav: function() {
      return $panes.mousemove(function(e) {
        var x;
        x = e.pageX - this.offsetLeft;
        if (!$body.hasClass("small")) {
          if (x > ($window.width() - 100) && x < ($window.width())) {
            $(".pane nav .next").stop(true, true).fadeIn("slow");
          } else {
            $(".pane nav .next").hide();
          }
          if (x < 100 && x > 0) {
            return $(".pane nav .previous").stop(true, true).fadeIn("slow");
          } else {
            return $(".pane nav .previous").hide();
          }
        }
      });
    },
    reposition: function() {
      var self;
      self = this;
      if (document.location.hash !== "") {
        $(scrollElement).stop().scrollLeft($(document.location.hash).offset().left);
        $menulinks.filter("[href=#home]").removeClass("active");
        $menulinks.filter("[href=" + document.location.hash + "]").addClass("active");
        if (document.location.hash === "#contact" && contact_loaded === 0) {
          self.asiance_map();
          contact_loaded = 1;
        }
        if (document.location.hash === "#work" && disable_modal === 1) {
          self.make_modal();
          return disable_modal = 0;
        }
      }
    }
  };
  "Asiance Ltd.";
}).call(this);
